interface Circle {
  kind: "circle";
  radius: number;
}
interface Rectangle {
  kind: "rectangle";
  width: number;
  height: number;
}
type ShapeEx = Circle | Rectangle;

function printArea(shape: Shape) {
  if ("radius" in shape) {
    console.log(Math.PI * shape.radius ** 2);
  } else {
    console.log(shape.width * shape.height);
  }
}

const circleex: Circle = { kind: "circle", radius: 5 };
const rectangleex: Rectangle = { kind: "rectangle", width: 10, height: 20 };

printArea(circleex); // 输出: 78.53981633974483
printArea(rectangleex); // 输出: 200
